package cn.south.campus.business.controller;

import cn.south.campus.business.model.req.GoodsReq;
import cn.south.campus.business.model.vo.GoodsVo;
import cn.south.campus.business.service.GoodsService;
import cn.south.campus.common.model.bo.Result;
import com.baomidou.mybatisplus.core.metadata.IPage;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 二手商品表 前端控制器
 * </p>
 *
 * @author chow
 * @since 2024-11-13
 */
@RestController
@RequestMapping("/campus/goods")
@AllArgsConstructor
public class GoodsController {

    private final GoodsService goodsService;

    @PostMapping("/publish")
    public Result<String> publishGoods(@RequestBody GoodsVo goodsVo) {
        goodsService.publishGoods(goodsVo);
        return Result.success("发布成功");
    }

    @PutMapping("changeStatus/{goodsId}/{status}")
    public Result<String> changeStatus(@PathVariable Integer status, @PathVariable Long goodsId) {
        goodsService.changeStatus(goodsId, status);
        return Result.success("修改成功");
    }

    @DeleteMapping("delete/{goodsId}")
    public Result<String> deleteGoods(@PathVariable Long goodsId) {
        goodsService.deleteGoods(goodsId);
        return Result.success("删除成功");
    }

    @GetMapping("/detailMe/{goodsId}")
    public Result<GoodsVo> getMeGoods(@PathVariable Long goodsId) {
        return Result.success(goodsService.getMeGoods(goodsId));
    }

    @PutMapping("/update")
    public Result<String> updateGoods(@RequestBody GoodsVo goodsVo) {
        goodsService.updateGoods(goodsVo);
        return Result.success("修改成功");
    }

    @GetMapping("/page")
    public Result<IPage<GoodsVo>> page(GoodsReq req) {
        return Result.success(goodsService.pageQuery(req));
    }

    @GetMapping("/pageMe")
    public Result<IPage<GoodsVo>> pageMe(GoodsReq req) {
        return Result.success(goodsService.pageQueryMe(req));
    }

    @GetMapping("/detail/{goodsId}")
    public Result<GoodsVo> getGoods(@PathVariable Long goodsId) {
        return Result.success(goodsService.getGoods(goodsId));
    }
}
